﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Yule8xCommon.Applib
{
    public class RedirectUtil
    {
        public static void RedirectTimer(bool result, string title, IList<string> messages, string url = "", int seconds = 3, string color = "")
        {
            url = string.IsNullOrEmpty(url) ? "history.go(-1);" : "location.href='" + url + "';";
            string html = "<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>操作结果</title><meta charset='utf-8' /><style type='text/css'> body{font-size:3rem;line-height:5rem; margin:1rem;} p, li{font-size:2.4rem; color:#555;} .success h3 { color: #090; } .success h3:after{content:':)'; margin-left:1rem;} .error h3 { color:#F00;} .error h3:after{content:':('; margin-left:1rem;} a { padding:0 1rem; text-decoration:none;} ul { list-style-type:decimal}</style></head><body><div class='" + (result ? "success" : "error") + "'><h3>" + title + "</h3><p><ul><li>" + string.Join("</li><li>", messages) + "</li></ul></p><p>即将进行<a href='#'>跳转</a>(<span id='seconds'>3</span>)...</p></div><script> var seconds = " + seconds + "; function countdonw() { seconds--; document.getElementById('seconds').innerText = seconds; if (seconds< 1) { " + url + " } } setInterval(countdonw, 1000);</script></body></html > ";
            ResponseUtil.WriteEnd(html);
        }
    }
}